<?php

namespace App\Console\Commands;

use App\Models\Currency;
use App\Models\Property;
use App\Models\User;
use Illuminate\Console\Command;

/**
 * 补全用户资产
 */
class SupplyProperty extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'supply:property';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        //获取当前所有在线币种
        $cids = Currency::where('online_switch', 1)->pluck('id')->toArray();
        //所有用户id
        $uids = User::where('status', 1)->pluck('id')->toArray();
        //寻找用户币种资产，不存在补充一条
        foreach ($cids as $cid) {
            foreach ($uids as $uid) {
                $property = Property::where(['cid' => $cid, 'uid' => $uid])->first();
                if (count($property) == 0) {
                    Property::create([
                        'cid'     => $cid,
                        'uid'     => $uid,
                        'balance' => 0,
                        'blocked' => 0,
                        'total'   => 0,
                    ]);
                }
            }
        }
    }
}
